package com.zc.im.common.msg;

import com.zc.im.common.constant.enums.EquipmentTypeEnum;
import com.zc.im.common.core.domain.BaseUserInfo;
import lombok.Data;

/**
 * Project：im
 * Date：2022/4/21
 * Time：15:57
 * Description：抽象基类
 *
 * @author Challen.Zhang
 * @version 1.0
 */
@Data
public abstract class AbstractMsg implements Msg {

    private String token;

    private transient BaseUserInfo userInfo;

    @Override
    public Long getUserId() {
        if (userInfo == null) {
            parseToken();
        }
        return userInfo.getUserId();
    }

    @Override
    public EquipmentTypeEnum getEquipmentType() {
        if (userInfo == null) {
            parseToken();
        }
        return userInfo.getEquipmentType();
    }

    @Override
    public BaseUserInfo getBaseUserInfo() {
        if (userInfo == null) {
            parseToken();
        }
        return userInfo;
    }

    @Override
    public String getUniqueKey() {
        if (userInfo == null) {
            parseToken();
        }
        return userInfo.getUniqueKey();
    }

    private void parseToken() {
        //todo 解析token
        BaseUserInfo userInfo = new BaseUserInfo();
        userInfo.setEquipmentType(EquipmentTypeEnum.WEB);
        this.userInfo = userInfo;
    }
}
